package com.zsc.shixun.utils;

import com.zsc.shixun.model.unauthorize.MessageVO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>
 * 生产者发送
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/11
 */
@Component
public class ProducerUtils {

    @Resource
    public RabbitTemplate rabbitTemplate;

    /**
     * 发送验证码消息
     *
     * @param mailto 邮箱
     * @param title  标题
     * @param cotent 内容
     */
    public void sendCode(String mailto, String title, String cotent) {
        MessageVO messageVO = new MessageVO();
        messageVO.setMailto(mailto);
        messageVO.setTitle(title);
        messageVO.setContent(cotent);

        rabbitTemplate.convertAndSend("code_exchange", "", messageVO);
    }

    /**
     * 发送通知消息
     *
     * @param mailto 邮箱
     * @param title  标题
     * @param cotent 内容
     */
    public void sendNotice(String mailto, String title, String cotent) {
        MessageVO messageVO = new MessageVO();
        messageVO.setMailto(mailto);
        messageVO.setTitle(title);
        messageVO.setContent(cotent);

        rabbitTemplate.convertAndSend("notice_exchange", "", messageVO);
    }

}
